home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / editors / mjovesrc.zoo / pcgetch.c < prev    next >
C/C++ Source or Header  |  1992-04-04  |  2KB  |  136 lines

  1. /***************************************************************************
  2.  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
  3.  * is provided to you without charge, and with no warranty.  You may give  *
  4.  * away copies of JOVE, including sources, provided that this notice is    *
  5.  * included in all the files.                                              *
  6.  ***************************************************************************/
  7.  
  8. #include "tune.h"
  9.  
  10. #ifdef    MSDOS
  11.  
  12. #include <bios.h>
  13. #include <dos.h>
  14.  
  15. #include "jove.h"
  16.  
  17. private void waitfun proto((void));
  18.  
  19. #ifdef    IBMPC
  20. private char last = '\0';
  21. extern int specialkey;
  22. #endif
  23.  
  24. int
  25. getrawinchar()
  26. {
  27. #ifdef    IBMPC
  28.     unsigned scan;
  29.  
  30.     if (specialkey = last) {
  31.         scan = last;
  32.         last = '\0';
  33.         return scan;
  34.     }
  35.  
  36.     while (!rawkey_ready())
  37.         waitfun();
  38.  
  39.     scan = _bios_keybrd(_KEYBRD_READ);
  40.     if ((scan&0xff) == 0) {
  41.         last = (char) (scan >> 8);
  42.         return 0xff;
  43.     }
  44.     return scan&0xff;
  45.  
  46. #else    /* !IBMPC */
  47. #ifdef    RAINBOW
  48.  
  49.     union REGS regs;
  50.  
  51.     while (!rawkey_ready())
  52.         waitfun();
  53.  
  54.     for (;;) {
  55.         regs.x.di = 2;
  56.         int86(0x18, ®s, ®s);
  57.         if (regs.h.al != 0)    /* should never happen, but who knows */
  58.             return regs.h.al;
  59.     }
  60. #else    /* !RAINBOW */
  61.  
  62.     while (!rawkey_ready())
  63.         waitfun();
  64.     return bdos(0x06, 0x00ff, 0xff) & 0xff;
  65. #endif    /* !RAINBOW */
  66. #endif    /* !IBMPC */
  67. }
  68.  
  69. private bool waiting = NO;
  70.  
  71. bool
  72. rawkey_ready()
  73. {
  74. #ifdef    IBMPC
  75.     if (waiting)
  76.         return NO;
  77.     if (last)
  78.         return YES;
  79.  
  80.     return _bios_keybrd(_KEYBRD_READY) != 0;
  81. #else    /* !IBMPC */
  82.     union REGS regs;
  83.  
  84.     if (waiting)
  85.         return NO;
  86. #ifdef    RAINBOW
  87.     regs.x.di = 4;
  88.     int86(0x18, ®s, ®s);
  89.     return regs.h.cl != 0;
  90. #else    /* !RAINBOW */
  91.     regs.h.ah = 0x44;        /* ioctl call */
  92.     regs.x.bx = 0;            /* stdin file handle */
  93.     regs.h.al = 0x06;        /* get input status */
  94.     intdos(®s, ®s);
  95.     return regs.h.al & 1;
  96. #endif    /* !RAINBOW */
  97. #endif    /* !IBMPC */
  98. }
  99.  
  100. #ifdef    IBMPC
  101. private long timecount, lastcount = 0;
  102. #else
  103. private char lastmin = 0;
  104. #endif
  105.  
  106.  
  107. private void
  108. waitfun()
  109. {
  110.     if (UpdModLine) {
  111.         waiting = YES;
  112.         redisplay();
  113.         waiting = NO;
  114.         return;
  115.     }
  116. #ifdef    IBMPC
  117.     if (_bios_timeofday(_TIME_GETCLOCK, &timecount) ||  /* after midnight */
  118.         (timecount > lastcount + 0x444) ) {
  119.         lastcount = timecount;
  120.         UpdModLine = YES;
  121.     }
  122. #else
  123.     {
  124.         struct dostime_t tc;
  125.  
  126.         _dos_gettime(&tc);
  127.         if (tc.minute != lastmin) {
  128.             UpdModLine = YES;
  129.             lastmin = tc.minute;
  130.         }
  131.     }
  132. #endif
  133. }
  134.  
  135. #endif    /* MSDOS */
  136.